use crate::{dto, mq};
use std::sync::Arc;

pub struct ClientManager {
    endpoint: Arc<mq::client::node::endpoint::Client>,
    pub srv6_config: Arc<mq::client::node::endpoint::srv6_config::Client>,
    pub wireguard_config: Arc<mq::client::node::endpoint::wireguard_config::Client>,
    pub peer: Arc<mq::client::node::endpoint::peer::client_manager::ClientManager>,
    pub traffic_steering_rule:
        Arc<mq::client::node::endpoint::traffic_steering_rule::client_manager::ClientManager>,
}

impl ClientManager {
    pub fn new(mq_client: Arc<mq::client::Client>) -> Self {
        Self {
            endpoint: Arc::new(mq::client::node::endpoint::Client::new(mq_client.clone())),
            srv6_config: Arc::new(mq::client::node::endpoint::srv6_config::Client::new(
                mq_client.clone(),
            )),
            wireguard_config: Arc::new(
                mq::client::node::endpoint::wireguard_config::Client::new(mq_client.clone()),
            ),
            peer: Arc::new(mq::client::node::endpoint::peer::client_manager::ClientManager::new(mq_client.clone())),
            traffic_steering_rule: Arc::new(
                mq::client::node::endpoint::traffic_steering_rule::client_manager::ClientManager::new(mq_client),
            ),
        }
    }

    pub async fn publish_setup_event(
        &self,
        node_id: &str,
        payload: dto::event::endpoint::SetupEventPayload,
    ) -> Result<(), anyhow::Error> {
        self.endpoint.publish_setup_event(node_id, payload).await
    }

    pub async fn publish_delete_event(
        &self,
        node_id: &str,
        payload: dto::event::endpoint::DeleteEventPayload,
    ) -> Result<(), anyhow::Error> {
        self.endpoint.publish_delete_event(node_id, payload).await
    }
}
